package cn.wangyazhu.SettlementRecord;

import cn.wangyazhu.SettlementRecord.model.User;
import cn.wangyazhu.SettlementRecord.service.UserRepository;
import lombok.AllArgsConstructor;
import lombok.Data;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

@Data
@Controller
@AllArgsConstructor
@RequestMapping("/")
public class UserController {

    @Autowired
    private UserRepository userRepository;

    @GetMapping()
    public String getLogin() {
        return "login";
    }


    @GetMapping("/register")
    public  String getRegister(ModelMap map) {
        map.addAttribute("user", new User());
        return "register";
    }

    @PostMapping("/createuser")
    public String createUser(@ModelAttribute User user) {
        userRepository.save(user);
        return "redirect:/";
    }


}
